package com.ldgk.pim.client.event;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.search.client.LocalResult;

/**
 * Requests a google local search to be performed
 *
 */
public class GLocalSearchEvent extends GwtEvent<GLocalSearchEventHandler>{
	public enum Type{START_SEARCH,RESULT_ARRIVED};
	
	private static final GwtEvent.Type<GLocalSearchEventHandler> TYPE = new GwtEvent.Type<GLocalSearchEventHandler>();

	private String centerPoint;
	private String searchString;
	private LocalResult result;
	
	private Type type;
	
	public GLocalSearchEvent(String centerPoint, String searchString){
		this.searchString = searchString;
		this.type = Type.START_SEARCH;
	}
	
	public GLocalSearchEvent(LocalResult result){
		this.result = result;
		this.type = Type.RESULT_ARRIVED;
	}	
	
	@Override
	protected void dispatch(GLocalSearchEventHandler handler) {
		if(this.type == Type.START_SEARCH ){
			handler.performSearch(this.centerPoint, this.searchString);
		}else{
			handler.resultArrived(this.result);
		}
	}

	@Override
	public com.google.gwt.event.shared.GwtEvent.Type<GLocalSearchEventHandler> getAssociatedType() {
		return TYPE;
	}

	public static GwtEvent.Type<GLocalSearchEventHandler> getType(){
		return TYPE;
	}
	
	public String getSearchString() {
		return searchString;
	}

	public void setSearchString(String searchString) {
		this.searchString = searchString;
	}
}
